package cn.edu.hunau.pojo;
import cn.edu.hunau.dao.ProductDao;
import cn.edu.hunau.dao.impl.ProductDaoImpl;
import cn.edu.hunau.utils.JsonUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author 苏佳
 * @Date 2022 12 11 22 58
 **/
public class ProductResult<T> {
    private List<T> path;
    private List<T> imagessrc;
    private List<T> goodsDetails;
    private Map<String,Object> goodsItem;

    /**
     * jdk7.0 的写法
     * @param data
     * @return
     */
    public static List<Map<String, Object>> loadDataStringToList(String data){
        String[] paths = data.split("\\|");
        List<Map<String, Object>> list = new ArrayList<>();
        for (int i = 0; i < paths.length; i++) {
            Map<String, Object> path = JsonUtils.stringToMap(paths[i], String.class, Object.class);
            list.add(path);
        }
        return list;
    }

    /**
     * jdk8.0 的写法
     * @param data
     * @return
     */
    public static List<Map<String, Object>> loadDataStringToList2(String data){
        String[] paths = data.split("\\|");
        return Arrays.stream(paths)
                .map(path->JsonUtils.stringToMap(path,String.class,Object.class))
                .collect(Collectors.toList());
    }


    public Map<String, Object> getGoodsItem() {
        return goodsItem;
    }

    public void setGoodsItem(Map<String, Object> goodsItem) {
        this.goodsItem = goodsItem;
    }


    public List<T> getPath() {
        return path;
    }

    public void setPath(List<T> path) {
        this.path = path;
    }

    public List<T> getImagessrc() {
        return imagessrc;
    }

    public void setImagessrc(List<T> imagessrc) {
        this.imagessrc = imagessrc;
    }

    public List<T> getGoodsDetails() {
        return goodsDetails;
    }

    public void setGoodsDetails(List<T> goodsDetails) {
        this.goodsDetails = goodsDetails;
    }
}
